package com.mianyang.zhangsan.controller;

import com.mianyang.zhangsan.common.base.BaseController;
import com.mianyang.zhangsan.common.base.R;
import com.mianyang.zhangsan.model.entity.SecStaticData;
import com.mianyang.zhangsan.service.SecStaticDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 静态配置(使用redis缓存)
 * @author jiangjr
 * @date 2023-01-17
 */
@RestController
@RequestMapping("/data")
public class SecStaticDataController extends BaseController {
    @Autowired
    private SecStaticDataService staticDataService;

    @GetMapping("/config")
    public R config(@RequestParam(value = "codeType") String codeType,
                    @RequestParam(value = "codeValue", required = false) String codeValue) {
        List<SecStaticData> cache = staticDataService.getCache(codeType, codeValue);
        return success("cache", cache);
    }

    @GetMapping("/version")
    public R refreshByVersion() {

        return success();
    }

    @GetMapping("/all")
    public R refreshByAll() {
        staticDataService.refresh();
        return success();
    }
}
